package dao.impl;

import dao.StaffInfoDao;
import entity.StaffsInfo;
import util.DBCoon;

import java.util.List;

/**
 * ClassName: StaffInfoDaoImpl
 * Description:
 *
 * @Author zjl
 * @Create 2025/02/24 20:05
 * @Version 1.0
 */
public class StaffInfoDaoImpl implements StaffInfoDao {
    @Override
    public List<StaffsInfo> list() {
        String sql = "select id, name, age, phone, sta_pos as staPos, add_time as addTime, update_time as updateTime from staffs";
        DBCoon.list(sql,StaffInfoDao.class);
        return list();
    }

    @Override
    public int add(StaffsInfo info) {
        String sql = "insert into staffs(name, age, phone, sta_pos as staPos, add_time as addTime) values(?,?,?,?,?) ";

        return DBCoon.update(sql, info.getName(), info.getAge(), info.getPhone(), info.getStaPos(), info.getAddTime());
    }

    @Override
    public int update(StaffsInfo info) {
        String sql = "update staffs set name = ?, age = ?, phone = ?, sta_pos = ?, update_time = ? where id = ?";
        return DBCoon.update(sql,info.getName(), info.getAge(), info.getPhone(), info.getStaPos(), info.getUpdateTime(), info.getId());
    }

    @Override
    public int delete(StaffsInfo id) {
        String sql = "delete from staffs where id = ?";
        return DBCoon.update(sql, id.getId());
    }
}
